home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00a.txt / 000018_icon-group-sender _Tue Feb 1 11:06:54 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id LAA00037
  4.     for icon-group-addresses; Tue, 1 Feb 2000 11:05:33 -0700 (MST)
  5. Message-Id: <200002011805.LAA00037@baskerville.CS.Arizona.EDU>
  6. From: dgamey@ca.ibm.com
  7. X-Lotus-FromDomain: IBMCA@IBMUS
  8. To: icon-group@optima.CS.Arizona.EDU
  9. cc: "Charles Hethcoat" <CHETHCOA@oss.oceaneering.com>
  10. Date: Mon, 31 Jan 2000 21:54:54 -0500
  11. Subject: Re: Updating array parameters in Icon (a mini-dissertation)
  12. Content-Disposition: inline
  13. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  14. Status: RO
  15.  
  16.  
  17.  
  18. Charles,
  19.  
  20. You are correct about icon's pointer semantics.   In (my paraphrase of)
  21. your example:
  22.  
  23.    procedure main()
  24.       x := []
  25.       method1( x )
  26.       method2( x )
  27.    end
  28.  
  29.    procedure method1(x)
  30.       x := [&e]
  31.       return
  32.    end
  33.  
  34.    procedure method2(x)
  35.       put(x, &pi)
  36.       return
  37.    end
  38.  
  39. You should expect that x will not be modified by method1.   The reason for
  40. this can be illustrated with the following:
  41.  
  42.    procedure main()
  43.    y := x := [1,2,3]
  44.    y[2] := 5
  45.    if x[2] = 5 then write("Changed") else write("Unchanged")
  46.    end
  47.  
  48. This program will write "Changed"
  49.  
  50. In both method1 and method2,  local/parameter x is assigned to main's x.
  51. In method1, local x is then assigned to a new list (creating a new
  52. structure in the block region).
  53. In method2, the contents of x are changed.  Since local x and main's x
  54. "point" to the same structure block (i.e. are identical === ), then the
  55. contents of that block are changed.
  56. In both cases, the local value of x is destroyed upon return.
  57.  
  58. You'll find this behaviour consistent amongst the structure objects that
  59. get allocated in the block region (lists, sets, tables, records).  Numbers
  60. and strings behave differently. (I'm not sure about csets, but I suspect
  61. they behave much like strings and numbers.)
  62.  
  63. David Gamey
  64.  
  65.  
  66.